package kgame5.k3d.core.render.layerrender.impl {
import kgame5.k3d.core.obj3d.info.geometry.Face3D;
import kgame5.k3d.core.obj3d.info.geometry.GeometryInfo;
import kgame5.k3d.core.obj3d.info.material.MaterialInfo;
import kgame5.k3d.core.obj3d.info.transform.TransformInfo;
import kgame5.k3d.core.render.RenderSessionData;
import kgame5.k3d.core.render.layerrender.LayerRender;

import flash.display.Shape;

/**
 * @author kangkai
 * 融合多个三角面的
 */
public class BestGroup3DLayerRender extends LayerRender{
	
	public function BestGroup3DLayerRender(){
		mc=new Shape();
		g=(mc as Shape).graphics;
	}
	
	//整个渲染BestGroup3D
	override public function  render(gi:GeometryInfo,mi:MaterialInfo,ti:TransformInfo,session:RenderSessionData):void{
		
		//面排序
		doSort(aOuterFace);
		
		//绘制,为每个三角面传送一次贴图
		doBestDraw(aOuterFace,session);
	}
	
	//真正画到屏幕上,为每个三角面单独传送贴图
	private function doBestDraw(aSortedFace:Array,session:RenderSessionData):void{
		//逐个画三角面,注意是只画出需要画的
		//var st4:int=getTimer();
		g.clear();//很重要的地方，画新的一定要注意清除

		for each(var face:Face3D in aSortedFace){
			face.drawBest(g);
		}

		//T.p("facCount:"+aSortedFace.length);
		g.endFill();
		//session.stati.drawTime+=(getTimer()-st4);
		
		//统计
		session.stati.renderedFaceCount+=aSortedFace.length;
		//--session.stati.faceCount+=faceCount;
		//--session.stati.vertexCount+=_vn;
	}
}
}
